package com.tf_cut.backend.seller.service;

import com.tf_cut.backend.common.pojo.PageInfo;
import com.tf_cut.backend.common.pojo.Result;
import com.tf_cut.backend.common.service.CommonServiceImpl;
import com.tf_cut.backend.mapper.SellerProjectMapper;
import com.tf_cut.backend.platform.vo.SetHistoryVo;
import com.tf_cut.backend.seller.pojo.SellerAccountDetail;
import com.tf_cut.backend.seller.repository.SellerAccountDetailRepository;
import com.tf_cut.backend.seller.repository.SellerAccountRepository;
import com.tf_cut.backend.seller.vo.SellerAccountDetailVo;
import com.tf_cut.backend.util.CopyUtil;
import com.tf_cut.backend.util.SerialNoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Service
@Transactional
public class SellerAccountDetailServiceImpl extends CommonServiceImpl<SellerAccountDetailVo, SellerAccountDetail, String> implements SellerAccountDetailService {

    @PersistenceContext
    private EntityManager em;

    @Autowired
    private SellerAccountRepository sellerAccountRepository;

    @Autowired
    private SellerAccountDetailRepository sellerAccountDetailRepository;
    
    @Autowired
    private SellerProjectMapper sellerProjectMapper;

    @Resource
    private SerialNoUtil util;

    @Override
    public void insert(SellerAccountDetailVo sellerAccountDetailVo,String merchantNumber,String platform){
        SellerAccountDetail sellerAccountDetail = CopyUtil.copy(sellerAccountDetailVo, SellerAccountDetail.class);


        String serialNo = util.genSerialNo("Q",platform,merchantNumber);

        sellerAccountDetail.setTradeId(serialNo);
//        sellerAccountDetailRepository.save(sellerAccountDetail);
    }

	@Override
	public PageInfo<SellerAccountDetailVo> queryDetail(int page, int rows, String projectCode) {
		com.github.pagehelper.PageHelper.startPage(page,rows);
        List<SellerAccountDetailVo> list = sellerProjectMapper.queryDetail(projectCode);
        com.github.pagehelper.PageInfo<SellerAccountDetailVo> pageInfo = new com.github.pagehelper.PageInfo<>(list);
		  PageInfo<SellerAccountDetailVo> returnPageInfo = new PageInfo<>();
	        returnPageInfo.setPage(pageInfo.getPageNum());
	        returnPageInfo.setPageSize(pageInfo.getPageSize());
	        returnPageInfo.setRows(pageInfo.getList());
	        returnPageInfo.setRecords((int) pageInfo.getTotal());
	        returnPageInfo.setTotal(pageInfo.getPages());
	        return returnPageInfo;
	}

	@Override
	public String updateStatu(String status, String projectCode) {
		sellerProjectMapper.updateStatu(status,projectCode);
		if(status.equals("T")){
			return "已复核";
		}else{
			return "已驳回";
		}
		
	}
}
